# Maintainer: Balló György <ballogyor+arch at gmail dot com>

pkgname=bt747
_pkgname=BT747
pkgver=2.2.1
pkgrel=2
pkgdesc="The swiss army knife for MTK GPS dataloggers"
arch=('any')
url="https://www.bt747.org/"
license=('GPL')
depends=('hicolor-icon-theme' 'java-rxtx')
makedepends=('imagemagick')
# Some files are missing from the 2.2.1 release, we need also the older one
source=(https://downloads.sourceforge.net/$pkgname/${_pkgname}_2.1.3_full.zip
        https://downloads.sourceforge.net/$pkgname/${_pkgname}_${pkgver}_en_full.zip
        https://www.bt747.org/icon/${pkgname}_128x128.gif
        $pkgname.desktop
        $pkgname.appdata.xml)
sha256sums=('b70bfb5a040e7ec687105e4092bc66f882dfa69fbbdd7971a5e9c649068ec615'
            '5f47c37116e3783c5942a9e181bb422bc06f951318b2e84df2fb21c951c9e08d'
            '6e2aa20d9fcdf44b8ac779f0a12a87480cd6f3f1b47127b250bac978c1d42149'
            '8e9b9528e2bf41627fb226ed1e4af31da70e734047fd33d0586fb8000cdcdb62'
            '6906e3c67d892859a361a148e4f90411214bea31f7b53695f6832d0dc6f44bb8')

prepare() {
  sed -i 's|^ROOT_DIR=.*|ROOT_DIR=/usr/share/java/bt747|
          s|"$JAVA" -jar "${ROOT_DIR}/dist/BT747_j2se.jar" arch|uname -m|
          s|amd64|x86_64|
          s|/usr/share/java/RXTXcomm.jar|/usr/share/java/rxtx/RXTXcomm.jar|
          s|bt747.j2se_view.BT747Main $\* &|-Dbt747_settings="`echo ~`/.config/bt747/bt747settings.pdb" bt747.j2se_view.BT747Main $\*|' ./run_j2se.sh

  convert +set date:create +set date:modify "${pkgname}_128x128.gif" "${pkgname}_128x128.png"
}

package() {
  _installdir="$pkgdir"/usr/share/java/$pkgname
  install -D -m644 lib/jchart2d-3.1.0.jar "$_installdir"/lib/jchart2d-3.1.0.jar
  install -D -m644 lib/jopt-simple-2.4.1.jar "$_installdir"/lib/jopt-simple-2.4.1.jar
  install -D -m644 lib/jcalendar-1.3.2.jar "$_installdir"/lib/jcalendar-1.3.2.jar
  install -D -m644 lib/swing-layout-1.0.3.jar "$_installdir"/lib/swing-layout-1.0.3.jar
  install -D -m644 lib/swingx.jar "$_installdir"/lib/swingx.jar
  install -D -m644 lib/swingx-ws.jar "$_installdir"/lib/swingx-ws.jar
  install -D -m644 dist/libBT747.jar "$_installdir"/dist/libBT747.jar
  install -D -m644 dist/BT747_j2se.jar "$_installdir"/dist/BT747_j2se.jar
  install -D -m755 ./run_j2se.sh "$pkgdir"/usr/bin/$pkgname
  install -D -m644 $pkgname.desktop "$pkgdir"/usr/share/applications/$pkgname.desktop
  install -D -m644 $pkgname.appdata.xml "$pkgdir"/usr/share/metainfo/$pkgname.appdata.xml
  install -D -m644 ${pkgname}_128x128.png "$pkgdir"/usr/share/icons/hicolor/128x128/apps/$pkgname.png
}
